package com.hexorld.sprite;

import java.util.Random;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.hexorld.core.Constants;
import com.hexorld.core.PassType;
import com.hexorld.core.UpdateFlag;
import com.hexorld.evoe.R;

public class Food extends VItem {
	private Random mRandom;

	public Food(Context context, int width, int height) {
		super(context, width, height);
		mPassType = PassType.PASS_GOT;
		mType = SpriteType.FOOD;
		mRandom = new Random();
	}

	public void initRes(){
		setBmpRes(R.drawable.watermelon);//default test bmp
	}
	
	public void spawn(){
		int x = mRandom.nextInt(Constants.GAME_BOARD_WIDTH - this.width);
		int y = mRandom.nextInt(Constants.GAME_BOARD_HEIGHT - this.height);
		setPosition(x, y);
		if(mCollisionManager != null && !mCollisionManager.requestRect(this, this.mDstRect))
			mSpawnHandler.sendEmptyMessage(0);
		else
			this.mVisible = true;
	}
	
	private Handler mSpawnHandler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			spawn();
		}
		
	};
	
	@Override
	public void update(UpdateFlag updateFlag) {
		if(updateFlag == UpdateFlag.SPAWN)
			mSpawnHandler.sendEmptyMessage(0);
	}
}
